[−][src]Crate shred
Shared resource dispatcher
This library allows to dispatch systems, which can have interdependencies, shared and exclusive resource access, in parallel.
Examples
extern crate shred; use shred::{DispatcherBuilder, Read, Resource, ResourceId, System, SystemData, World, Write}; #[derive(Debug, Default)] struct ResA; #[derive(Debug, Default)] struct ResB; #[derive(SystemData)] // Provided with `shred-derive` feature struct Data<'a> { a: Read<'a, ResA>, b: Write<'a, ResB>, } struct EmptySystem; impl<'a> System<'a> for EmptySystem { type SystemData = Data<'a>; fn run(&mut self, bundle: Data<'a>) { println!("{:?}", &*bundle.a); println!("{:?}", &*bundle.b); } } fn main() { let mut world = World::empty(); let mut dispatcher = DispatcherBuilder::new() .with(EmptySystem, "empty", &[]) .build(); world.insert(ResA); world.insert(ResB); dispatcher.dispatch(&mut world); }
Once you are more familiar with how system data and parallelization works,
you can take look at a more flexible and performant way to dispatch:
ParSeq
. Using it is bit trickier, but it allows dispatching without any
virtual function calls.
Modules
cell | Helper module for some internals, most users don't need to interact with it. |
Macros
par | The |
seq | The |
Structs
AsyncDispatcher | Like, |
BatchAccessor | The |
BatchUncheckedWorld | The |
DefaultBatchControllerSystem | The |
DefaultProvider | A |
Dispatcher | The dispatcher struct, allowing systems to be executed in parallel. |
DispatcherBuilder | Builder for the |
Entry | An entry to a resource of the |
Fetch | Allows to fetch a resource in a system immutably. |
FetchMut | Allows to fetch a resource in a system mutably. |
MetaIter | An iterator for the |
MetaIterMut | A mutable iterator for the |
MetaTable | The |
PanicHandler | A setup handler that simply does nothing and thus will cause a panic on
fetching. The panic will provide the type name if the |
Par | Runs two tasks in parallel.
These two tasks are called |
ParSeq | A dispatcher intended to be used with
|
Read | Allows to fetch a resource in a system immutably. |
ResourceId | The id of a |
Seq | Runs two tasks sequentially.
These two tasks are called |
StaticAccessor | The static accessor that is used for |
World | A Resource container, which provides methods to insert, access and manage the contained resources. |
Write | Allows to fetch a resource in a system mutably. |
Enums
AccessorCow | Either an |
RunningTime |
Traits
Accessor | A trait for accessing read/write multiple resources from a system. This can be used to create dynamic systems that don't specify what they fetch at compile-time. |
BatchController | The |
CastFrom | Helper trait for the |
DynamicSystemData | A struct implementing system data indicates that it bundles some resources which are required for the execution. |
Resource | A resource is a data slot which lives in the |
RunNow | Trait for fetching data and running systems. Automatically implemented for systems. |
RunWithPool | Similar to |
SetupHandler | A setup handler performing the fetching of |
System | A |
SystemData | A static system data that can specify its dependencies at statically (at
compile-time). Most system data is a |
Type Definitions
ReadExpect | Allows to fetch a resource in a system immutably.
This will panic if the resource does not exist.
Usage of |
Resources | Deprecated Alias for |
WriteExpect | Allows to fetch a resource in a system mutably.
This will panic if the resource does not exist.
Usage of |
Derive Macros
SystemData | A reexport of the |